package com.atchangsha.system.controller;

import java.util.Arrays;
import java.util.Map;

import com.atchangsha.system.dto.SalesBillDTO;
import org.springframework.web.bind.annotation.*;
import com.atchangsha.system.entity.SalesBillEntity;
import com.atchangsha.system.service.SalesBillService;
import com.atchangsha.system.common.utils.PageUtils;
import com.atchangsha.system.common.utils.Result;
import javax.annotation.Resource;

/**
 * 消费记录表
 * @author 卓越班项目第二组
 * @date 2022-04-22 00:49:59
 */
@RestController
@RequestMapping("system/salesBill")
@CrossOrigin
public class SalesBillController {
    @Resource
    private SalesBillService salesBillService;

    /**
     * 分页查询消费账单列表
     */
    @GetMapping("/list")
    public Result list(@RequestParam Map<String, Object> params){
        PageUtils page = salesBillService.queryPage(params);

        return Result.ok().setResult(page);
    }


    /**
     * 根据消费账单id查看详情
     */
    @GetMapping("/info/{id}")
    public Result info(@PathVariable("id") Long id){
		SalesBillEntity salesBill = salesBillService.getById(id);

        return Result.ok().setResult(salesBill.toEntity());
    }

    /**
     * 生成消费账单
     */
    @PostMapping("/save")
    public Result save(@RequestBody SalesBillDTO salesBillDTO){
		return salesBillService.add(salesBillDTO);
    }

    /**
     * 修改
     */
    @PutMapping("/update")
    public Result update(@RequestBody SalesBillEntity salesBill){
		salesBillService.updateById(salesBill);

        return Result.ok();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete")
    public Result delete(@RequestParam Long[] ids){
		salesBillService.removeByIds(Arrays.asList(ids));

        return Result.ok();
    }

}
